/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.moviesgoodies.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Thibault
 */
@Entity
@Table(catalog = "moviesgoodies", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Commande.findAll", query = "SELECT c FROM Commande c"),
    @NamedQuery(name = "Commande.findById", query = "SELECT c FROM Commande c WHERE c.id = :id"),
    @NamedQuery(name = "Commande.findByMontantTTC", query = "SELECT c FROM Commande c WHERE c.montantTTC = :montantTTC"),
    @NamedQuery(name = "Commande.findByNoConfirmation", query = "SELECT c FROM Commande c WHERE c.noConfirmation = :noConfirmation"),
    @NamedQuery(name = "Commande.findByDateCreation", query = "SELECT c FROM Commande c WHERE c.dateCreation = :dateCreation"),
    @NamedQuery(name = "Commande.findByDateAnnulation", query = "SELECT c FROM Commande c WHERE c.dateAnnulation = :dateAnnulation")})
public class Commande implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(nullable = false)
    private Integer id;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Basic(optional = false)
    @NotNull
    @Column(nullable = false, precision = 5, scale = 2)
    private BigDecimal montantTTC;
    @Size(max = 45)
    @Column(length = 45)
    private String noConfirmation;
    @Basic(optional = false)
    @NotNull
    @Column(nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateCreation;
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateAnnulation;
    @JoinColumn(name = "Client_Id", referencedColumnName = "Id", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Client clientId;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "commande", fetch = FetchType.LAZY)
    private List<ProduitCommande> produitCommandeList;

    public Commande() {
    }

    public Commande(Integer id) {
        this.id = id;
    }

    public Commande(Integer id, BigDecimal montantTTC, Date dateCreation) {
        this.id = id;
        this.montantTTC = montantTTC;
        this.dateCreation = dateCreation;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public BigDecimal getMontantTTC() {
        return montantTTC;
    }

    public void setMontantTTC(BigDecimal montantTTC) {
        this.montantTTC = montantTTC;
    }

    public String getNoConfirmation() {
        return noConfirmation;
    }

    public void setNoConfirmation(String noConfirmation) {
        this.noConfirmation = noConfirmation;
    }

    public Date getDateCreation() {
        return dateCreation;
    }

    public void setDateCreation(Date dateCreation) {
        this.dateCreation = dateCreation;
    }

    public Date getDateAnnulation() {
        return dateAnnulation;
    }

    public void setDateAnnulation(Date dateAnnulation) {
        this.dateAnnulation = dateAnnulation;
    }

    public Client getClientId() {
        return clientId;
    }

    public void setClientId(Client clientId) {
        this.clientId = clientId;
    }

    @XmlTransient
    public List<ProduitCommande> getProduitCommandeList() {
        return produitCommandeList;
    }

    public void setProduitCommandeList(List<ProduitCommande> produitCommandeList) {
        this.produitCommandeList = produitCommandeList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Commande)) {
            return false;
        }
        Commande other = (Commande) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "fr.moviesgoodies.entity.Commande[ id=" + id + " ]";
    }
    
}
